package view.elaborationview;


import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionListener;

import design.graphic.SinglePanel;

/**rappresenta un pannello in cui  vengono caricati solo JButton. Utilizzato nella Elaboration View
 * 
 * @author koldar
 * @version 1.0
 *
 */
public class JButtonPanel extends SinglePanel<JIDButton>{

	private static final long serialVersionUID = 1730469265857485685L;
	/**indica il numero totale di righe nella tabella*/
	protected int totalgridx;
	/**indica il contenitore di informazioni del GridLayout*/
	protected GridBagConstraints info;
	
	public JButtonPanel(int _gridx){
		super();
		this.totalgridx=_gridx;
		this.info=new GridBagConstraints();
		this.info.gridx=0;
		this.info.gridy=0;
		this.setLayout(new FlowLayout());
		//this.setLayout(new GridBagLayout());
	}
	/**aggiunge il compoenente dato e setta le sue dimensioni minime a quelle passate dall'utente
	 * 
	 * @param cmp il componente da agigungere
	 * @param dimx la dimensione minima x
	 * @param dimy la dimensione minima y
	 */
	public void add(Component cmp,int dimx,int dimy){
		this.add(cmp).setMinimumSize(new Dimension(dimx,dimy));
	}
	public JIDButton add(Component cmp){
		super.add(cmp);
		//this.add(cmp,info);
		if (this.info.gridx<this.totalgridx){
			this.info.gridx++;
		}else{
			this.info.gridx=0;
			this.info.gridy++;
		}
		return this.get(this.getComponentCount()-1);
		
	}
	public void addActionListeners(ActionListener e){
		for (int i=0;i<this.getComponentCount();i++){
			this.get(i).addActionListener(e);
		}
	}

}
